<?php
include('../includes/common.php');
if ($islogin != 1) {
	exit('<script language=\'javascript\'>window.location.href=\'./login.php\';</script>');
}
$act = isset($_GET['act']) ? daddslashes($_GET['act']) : null;

@header('Content-Type: application/json; charset=UTF-8');
switch ($act) {
    case 'setdorm': //宿舍状态更改
        $id = intval($_GET['id']);
        $state = intval($_GET['state']);
        $rs = $conn->query("update dorm_list set state='$state' where id='{$id}'");
        exit('{"code":0,"msg":"succ"}');
        break;
    case 'setUser': //用户状态更改
        $id = intval($_GET['id']);
        $state = intval($_GET['state']);
        $rs = $conn->query("update user_list set state='$state' where id='{$id}'");
        exit('{"code":0,"msg":"succ"}');
        break;
    case 'getInfo': //查看宿舍详细信息
        $id = intval($_GET['id']);
        $rs = $conn->query("select * from dorm_list where id='$id' limit 1");
        if (!$rs)
            exit('{"code":-1,"msg":"当前宿舍不存在！"}');
        $res = $rs->fetch_assoc();
        if ($res['state'] == 1) {
            $state = '正常';
        } else {
            $state = '封禁';
        }
        $result = array("code" => 0, "msg" => "succ", "id" => $res['id'], "uid" => $res['uid'],  "state" => $state,  "remarks" => $res['remarks'],  "name" => $res['name'], "money" => $res['money'], "addtime" => $res['addtime']);
        exit(json_encode($result));
        break;
    case 'getInfo2': //查看回收站网址详细信息
        $id = intval($_GET['id']);
        $rs = $conn->query("select * from dorm_list where id='$id' and deltime is not null limit 1");
        if (!$rs)
            exit('{"code":-1,"msg":"当前网址不存在！"}');
        $res = $rs->fetch_assoc();
        if ($res['state'] == 1) {
            $state = '正常';
        } else {
            $state = '封禁';
        }
        $vrs = $conn->query("select * from visitors where urlid = '{$res["id"]}'");
        $viewNum = $vrs->num_rows;
        $result = array("code" => 0, "msg" => "succ", "id" => $res['id'], "uid" => $res['uid'], "setip" => $res['setip'], "state" => $state, "url" => $res['url'], "remarks" => $res['remarks'], "qqjump" => $res['qqjump'], "wxjump" => $res['wxjump'], "alijump" => $res['alijump'], "tcn" => $res['tcn'], "urlcn" => $res['urlcn'], "view" => $viewNum, "pwd" => $res['pwd'], "addtime" => $res['addtime'], "deltime" => $res['deltime']);
        exit(json_encode($result));
        break;
    case 'delSelect': //宿舍全选删除
        $id = explode('&', $_POST['str']);
        $i = 0;
        while ($i < count($id)) {
            $conn->query("delete from dorm_list where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
    case 'upSelect': //宿舍全选修改
        $id = explode('&', $_POST['str']);
        $i = 0;
        $url = $_GET['url'];
        while ($i < count($id)) {
            $conn->query("update dorm_list set url = '$url' where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
    case 'delSelect2': //记录全选删除
        $id = explode('&', $_POST['str']);
        $i = 0;
        while ($i < count($id)) {
            $conn->query("delete from rmb_list where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
    case 'delSelect3': //用户全选删除
        $id = explode('&', $_POST['str']);
        $i = 0;
        while ($i < count($id)) {
            $conn->query("delete from user_list where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
	case 'delSelect4': //日志全选删除
        $id = explode('&', $_POST['str']);
        $i = 0;
        while ($i < count($id)) {
            $conn->query("delete from log_list where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;	
    case 'stateAll': //全选宿舍状态修改
        $state = $_GET['state'];
        $id = explode('&', $_POST['str']);
        $i = 0;
        while ($i < count($id)) {
            $conn->query("update dorm_list set state='$state' where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
    case 'site': //修改站点信息
        foreach ($_POST as $k => $value) {
            if ($k == 'pwd') continue;
            $value = daddslashes($value);
            $conn->query("insert into config set `k`='{$k}',`v`='{$value}' on duplicate key update `v`='{$value}'");
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
}
